package com.travel.photos.ui.find;

import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.ldoublem.loadingviewlib.LVChromeLogo;
import com.travel.R;
import com.travel.photos.base.BaseFragment;

import butterknife.Bind;
import butterknife.ButterKnife;
import tools.EndLessOnScrollListener;

/**
 * Created by meidou on 2016/10/18.
 * 发现的fragment
 */

public class PhotoVpFindFragment extends BaseFragment implements GirlOnClickListener,FindContract.View{
    @Bind(R.id.photot_recycle)
    RecyclerView mPhototRecycle;
    @Bind(R.id.photo_swp)
    SwipeRefreshLayout mPhotoSwp;
    private LinearLayoutManager mManager;
    private FindPresenter mPresenter;
    @Override
    public void initData() {//加载数据
        mPresenter = new FindPresenter(this);
        mPresenter.getDetail(getActivity());
    }
    @Override
    protected void initView() {
        //设置recycleview
        mManager = new LinearLayoutManager(getContext());
        mManager.setOrientation(LinearLayoutManager.VERTICAL);
        mPhototRecycle.setLayoutManager(mManager);
        mPhototRecycle.setItemAnimator(new DefaultItemAnimator());
        //下拉刷新
        mPhotoSwp.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
           mPresenter.DownRefresh(getContext());
            }
        });
        //上拉加载
        mPhototRecycle.addOnScrollListener(new EndLessOnScrollListener(mManager) {
            @Override
            public void onLoadMore(int currentPage) {
                mPresenter.PullUpRefresh(getContext());
            }
        });
    }
//布局
    @Override
    public int getLayoutId() {
        return R.layout.photo_vp_find;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
    @Override
    public void getDetail(FindAdapter adapter) {
        mPhototRecycle.setAdapter(adapter);
        mPhotoSwp.setRefreshing(false);

    }
    @Override
    public void viewGirlPhoto(String s) {
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        GirlPhotoFragment fragment = GirlPhotoFragment.newInstance(s);
        fragment.show(fragmentManager, "fragment_girl_photo");
        fragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog_FullScreen);
    }
}
